//
//  HLMineCell.m
//  YueYue
//
//  Created by hulu001 on 2023/5/19.
//

#import "HLMineCell.h"

@interface HLMineCell ()

@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UISwitch *switchButton;
@property (nonatomic, strong) UIImageView *arrowView;

@end

@implementation HLMineCell


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = UIColorClear;
        self.contentView.backgroundColor = UIColorClear;
        [self setupUI];
    }
    return self;
}


- (void)setupUI
{
    self.containerView = [[UIView alloc] init];
    _containerView.backgroundColor = UIColorWhite;
    [self.contentView addSubview:_containerView];
    [_containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
    }];
    self.iconView = [[UIImageView alloc] init];
    _iconView.image = UIImageMake(@"mine_greet_icon");
    [_containerView addSubview:_iconView];
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(0);
    }];
    
    self.titleLabel = [[UILabel alloc] init];
    _titleLabel.font = UIFontMake(15);
    _titleLabel.textColor = HLTextColor1;
    _titleLabel.text = @"招呼设置";
    [_containerView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.bottom.mas_equalTo(-20);
        make.left.equalTo(_iconView.mas_right).offset(12);
    }];
    
    self.arrowView = [[UIImageView alloc] init];
    _arrowView.image = UIImageMake(@"mine_arrow_icon");
    [_containerView addSubview:_arrowView];
    [_arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-16);
    }];
    
    self.switchButton = [[UISwitch alloc] init];
    _switchButton.hidden = YES;
    [_containerView addSubview:_switchButton];
    [_switchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-16);
    }];
    
    self.detailLabel = [[UILabel alloc] init];
    _detailLabel.font = UIFontMake(15);
    _detailLabel.textColor = HLTextColor2;
    _detailLabel.numberOfLines = 2;
    _detailLabel.textAlignment = NSTextAlignmentRight;
    [_containerView addSubview:_detailLabel];
    [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.equalTo(_containerView.mas_centerX).offset(-30);
        make.right.equalTo(_arrowView.mas_left).offset(-4);
    }];
}


- (void)setModel:(HLMineCellModel *)model
{
    _model = model;
    _iconView.hidden = YES;
    
    
    if (model.icon.length > 1){
        _iconView.hidden = NO;
        _iconView.image = UIImageMake(model.icon);
    }else {
        [self.containerView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.mas_equalTo(0);
        }];
        
        [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(16);
            make.top.mas_equalTo(18);
            make.bottom.mas_equalTo(-18);
        }];
    }
    
    _titleLabel.text = model.title;
    _arrowView.hidden = !model.hasDetail;
    _switchButton.hidden = !model.hasSwitch;
    _detailLabel.text = model.detail;
    if ([model.detail isEqualToString:@"未编辑"]){
        _detailLabel.textColor = HLAideColor1;
    } else {
        _detailLabel.textColor = HLTextColor2;
    }
}

@end
